﻿/////////////////////////////////////////////////////////////////
//File: ArticleInfo.cs
//Description: 
//  Ajax 代码
//  
//Copyright© 2011 Moliu
//History:
//  2011-2-23 23:28:31    CodeSmith5.0.1    Original Version
/////////////////////////////////////////////////////////////////

using System;
using System.Threading;
using System.Collections.Generic;
using System.IO;
using MAF.Common;
using My.Blog.Domain.Entities;
using My.Blog.Domain.Interfaces;
using My.Blog.Business.Service;
using My.Blog.Business.Security;
using My.Blog.Web.Controllers;
using System.Configuration;
using System.Collections.Specialized;
using System.Web;
using NVelocity.App;
using Commons.Collections;
using NVelocity;
using NVelocity.Runtime;

namespace My.Blog.Web.UI
{
    public class ArticleDetail : My.Blog.Web.Controllers.BasePage
    {
        public ArticleDetail()
        {
            string TPL_FILE_PATH = ConfigurationManager.AppSettings["TemplatesPath"]; // 模板路径
                                 //+ @"/ArticleDetail.html";
            HttpContext context = HttpContext.Current;                               // 当前Http上下文

            // 处理模板
            // 第一步，创建一个VelocityEngine
            //VelocityEngine velocity = new VelocityEngine(new ExtendedProperties());
            //velocity.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); 
            //ExtendedProperties props = new ExtendedProperties();
            //velocity.Init(props);

            VelocityEngine vltEngine = new VelocityEngine();
            // 文件型模板, 还可以是 "assembly", 则使用资源文件  
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            // 模板存放目录  
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, context.Server.MapPath("_UI/V1/"));
            vltEngine.Init();  

            // 第二步，创建一个Template
            NVelocity.Template template = vltEngine.GetTemplate("ArticleDetail.html");

            // 第三步，合并模板
            VelocityContext vContext = new VelocityContext();
            vContext.Put("RootUrl", this.RootUrl);
            vContext.Put("IsMasterMode",this.IsMasterMode);
            vContext.Put("ArticleInfo", new ArticleHandler(this).ReadArticleByConditions()); // 数据源

            StringWriter writer = new StringWriter();
            template.Merge(vContext, writer);
            context.Response.Write(writer.GetStringBuilder().ToString());
        }
    }
}

